﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Base.cshtml";
}
<table border="0" width="100%">
    <tr>
        <td valign="middle" align="left" width="400px">
            <span style="font-size: 14px">担保公司:</span><select id="ddlguaranteeCompany" name="ddlguaranteeCompany"
                class="selectpicker" data-style="btn-info" data-width="300px" style="margin-top: 10px">
            </select>
        </td>
        <td valign="middle" align="left" width="350px">
            <span style="font-size: 14px">关键字:</span>
            <input id="txtKey" name="txtKey" type="text" class="input-medium search-query" placeholder="编码/名称等"
                style="width: 250px; background-color: #fff;" />
        </td>
        <td valign="middle" align="left">
            <button class="btn btn-primary btn-small" id="btnSearch">
                查询
            </button>
        </td>
    </tr>
</table>
<div style="width:99%;height:1px;overflow:hidden;background-color:#dddddd;margin:10px"></div>
<table id="projectgrid" class="mmg">
    <tr>
        <th rowspan="" colspan="">
        </th>
    </tr>
</table>
<div id="pg" style="text-align: right;">
</div>
@section tail{
    <script src="/content/plugins/mmgrid/mmGrid.js" type="text/javascript"></script>
    <script src="/content/plugins/mmgrid/mmPaginator.js" type="text/javascript"></script>
    @*<script src="/content/plugins/bootbox.min.js"></script>*@
    <script type="text/javascript">

        var cols = [

        { title: '项目编码', name: 'ProjectCode', width: 60, align: 'center' },
        { title: '项目名称', name: 'ProjectTitle', width: 100, align: 'center' },
        { title: '产品名称', name: 'ProductName', width: 60, align: 'center' },
        { title: '借款企业', name: 'EnterpriseName', width: 100, align: 'center', renderer: function (val, item, index) {

            return item["Enterprise"]["EnterpriseName"] + "(" + item["OriginalRate"] + "%" + ")";
        }
        },
        { title: '借款金额', name: 'CycleAmount', width: 80, align: 'center', renderer: function (val, item, index) {

            return "&yen" + Number(item["Financing"] / 10000).toFixed(2) + "万元";
        }
        },

        { title: '年化利率', name: 'OriginalRate', width: 30, align: 'center', renderer: function (val, item, index) {

            return item["Policy"]["Rate"] + "%";
        }
        },
        { title: '借款时长', name: 'Duration', width: 40, align: 'center', renderer: function (val, item, index) {
            var durationType = item["Policy"]["DurationType"] == 0 ? "天" : "月";
            return (item["CycleAmount"] * item["Policy"]["Duration"]) + durationType;
        }
        },
        { title: '担保公司', name: 'CompanyName', width: 80, align: 'center', renderer: function (val, item, index) {
            return item["GuaranteeCompany"]["CompanyName"] + "(" + item["GuaranteeRate"] + "%" + ")";
        }
        },
        { title: '状态', name: 'Status', width: 30, align: 'center', renderer: function (val, item, index) {

            if (parseInt(item["Status"]) == 1) return '已提交';
            else if (parseInt(item["Status"]) == 2) return '审核中';
        }
        },
        { title: '操作', name: 'ID', width: 80, align: 'center', lockWidth: true, lockDisplay: true, renderer: function (val, item, index) {
            var html = "";

            html = '<button class="btn btn-info btn-mini"  onclick="grid_project_audit(\'' + item["ID"] + '\')">审核</button>';

            return html;
        }
        }
    ];

        var mmg;
        var ddlguaranteeCompany;

        $(function () {

            bindGuaranteeCompany();
            mmg = $('#projectgrid').mmGrid({
                indexCol: true,
                indexColWidth: 25,
                height: $("body", parent.document).height() - 250,
                cols: cols,
                url: '/ProjectAudit/GetProjectListForAudit',
                method: 'get',
                remoteSort: true,
                //items: items,
                //sortName: 'SECUCODE',
                //sortStatus: 'asc',
                multiSelect: false,
                checkCol: false,
                fullWidthRows: true,
                autoLoad: false,
                plugins: [
                        $('#pg').mmPaginator()
                    ]
            });
            mmg.load();
            $("#btnSearch").click(function () {

                search();

            });
        });
        function bindGuaranteeCompany() {
            $.ajax({
                url: "/GuarCompany/GetGuarCompanyListByKey",
                data: null,
                type: "get",
                success: function (result) {
                    result = eval("(" + result + ")");
                    ddlguaranteeCompany = $("#ddlguaranteeCompany");
                    ddlguaranteeCompany.empty(); //清空select下拉框

                    for (var i = 0; i < result.length; i++) {
                        $("<option value='" + result[i].ID + "'>" + result[i].CompanyName + "</option>").appendTo(ddlguaranteeCompany)//动态添加Option子项
                    }
                    ddlguaranteeCompany = ddlguaranteeCompany.selectpicker('show');
                }
            });

        }
        function search() {
            mmg.setParm({ key: $("#txtKey").val(), guaranteeCompanyID: ddlguaranteeCompany.val() });
            mmg.load({ page: 1 });
        }
        function grid_project_audit(projectID) {
            location.href = decodeURIComponent("/ProjectAudit/ProjectAudit?projectID=" + projectID);
        }
         
    </script>
}
